package com.sff.utils {
	import flash.net.SharedObject;
	import flash.utils.Proxy;
	import flash.utils.clearTimeout;
	import flash.utils.flash_proxy;
	import flash.utils.setTimeout;
	
	//return Base64.encode( String( new Date( ).getTime( ) * Math.random( ) ) );
		
	public dynamic class Cookies extends Proxy {
		
		private var _so 		: SharedObject;
		private var _timeout 	: int;
		
		public function Cookies( name : String ) {
			_init( name );
		}

		override flash_proxy function getProperty( name : * ) : * {
			return _so.data[String(name)];
		}

		override flash_proxy function setProperty( name : *, value : * ) : void {
			_so.data[ String(name) ] = value;
			_invalidate();
		}

		override flash_proxy function deleteProperty(name : *) : Boolean {
			return delete _so.data[ String(name) ];
		}

		private function _invalidate() : void {
			clearTimeout( _timeout );
			_timeout = setTimeout( _flush, 500 );
		}
		
		private function _flush( ) : void {
			clearTimeout( _timeout );
			_so.flush();	
		}

		private function _init( name : String ) : void {
			_so = SharedObject.getLocal( name , "/" );
		}		
	}
}